1   /************************************************************
2   *                     Copyright                            *
3   * Portions of this software are Copyright (c) 1993 - 2002, *
4   * Chad Z. Hower (Kudzu) and the Indy Pit Crew              *
5   *  - http://www.nevrona.com/Indy/                          *
6   ************************************************************/
7   package org.indy;
8   
9   import org.indy.util.StringList;
10  
11  
12  /***
13   * <code>Command</code> represents information about commands received
14   * by a {@link TCPServer} for an executing {@link PeerThread},
15   * and handled using a {@link CommandHandler}.
16   *
17   * <code>Command</code> provides properties that identify the Thread generating the command, and the CommandHandler used to service the command. In addition, TIdCommand also implements methods that allow assigning the response for the command, and a mechanism for sending the command reply using the
18   * thread connection that generated the command request.
19   *
20   * <code>Command</code> instances are created in {@link CommandHandler#check(String,PeerThread)}
21   * when a given command can be handled by the <code>CommandHandlers</code>
22   * for the server, using the <code>PeerThread</code> that is executed in the
23   * <code>TCPServer</code> context.
24   *
25   *
26   *@author    OTG
27   *@version   1.0
28   *
29   *@see    CommandHandler
30   *@see    CommandHandler#check(String,PeerThread)
31   *@see    TCPServer
32   *@see    PeerThread
33   *@see    RFCReply
34   */
35  public final class CommandEvent {
36    private CommandHandler commandHandler;
37    private boolean performReply;
38    private StringList params = new StringList();
39    private String rawLine;
40    private RFCReply reply;
41    private final StringList response = new StringList();
42    private PeerThread thread;
43    private String unparsedParams;
44  
45    /***
46   *  Constructs a new, blank, <code>CommandEvent</code> instance.
47   */
48    CommandEvent() {
49    }
50  
51    /***
52   *  Sets whether or not the {@link RFCReply} returned
53   *  by {@link getReply()} should be sent back to the peer.
54   *
55   *@param  performReply  The new performReply value
56   *@see getPerformReply()
57   *@see getReply()
58   *@see RFCReply
59   */
60    public void setPerformReply(boolean performReply) {
61      this.performReply = performReply;
62    }
63  
64    /***
65   * Sets the {@link RFCReply} to be sent back to the peer.
66   *
67   * @param  reply  The new {@link RFCReply} obect to use.
68   * @see #getReply()
69   * @see RFCReply
70   */
71    public void setReply(RFCReply reply) {
72      this.reply = new RFCReply(reply);
73    }
74  
75    /***
76   *  Sets the {@link IdStrings} to use as a resopnse for this command
77   *
78   *@param  response  The new response value
79   */
80    public void setResponse(StringList response) {
81      this.response.copy(response);
82    }
83  
84    /***
85   * CommandHandler is a read-only {@link CommandHandler}
86   * property that represents the command handler that
87   * created the <code>CommandEvent</code> object instance.
88   *
89   * The <code>CommandHandler</code> is assigned when the
90   * object instance is created as the peer thread
91   * is executed in {@link CommandHandler#check(String,PeerThread)}.
92   *
93   *@return    This <code>CommandEvent</code> handler.
94   *@see CommandHandler
95   *
96   */
97    public CommandHandler getCommandHandler() {
98      return commandHandler;
99    }
100 
101   /***
102  * Returns whether the {@link RFCReply} returned by
103  * {@link #getReply()} should be sent back to the peer
104  * in reponse.
105  *
106  *@return    Whether this command is set to reply or not.
107  *@see getPeformReply
108  *@see RFCReply
109  */
110   public boolean getPerformReply() {
111     return performReply;
112   }
113 
114   /***
115  * Returns the parameters associated with this <code>Command</code>
116  * as a {@link org.indy.util.StringList}.
117  *
118  * If the creating {@link CommandHandler} had it's <code>parseParams</code>
119  * property set to <code>true</code> then the <code>StringList</code>
120  * will contain the parameters tokenised using the <code>CommandHandler<code>'s
121  * command delimiter. Otherwise the list will just contain the unparsed
122  * parameteters as a single string.
123  *
124  *@return    A collection of strings representing the parameters sent with this command.
125  */
126   public StringList getParams() {
127     return params;
128   }
129 
130   /***
131  *  Gets the raw line that was sent to the server for this command.
132  *
133  *@return    The raw line that was sent to the server for this command.
134  */
135   public String getRawLine() {
136     return rawLine;
137   }
138 
139   /***
140  *  Gets the {@link org.indy.RFCReply} associated with this command.
141  *
142  *@return    The associated <code>RFCReply</code> object.
143  */
144   public RFCReply getReply() {
145     return reply;
146   }
147 
148   /***
149  *  Gets the response attribute of this <code>Command</code> as a {@link org.indy.util.StringList}
150  *
151  *@return    The response value
152  */
153   public StringList getResponse() {
154     return response;
155   }
156 
157   /***
158  *  Gets the {@link PeerThread} that is handling this command.
159  *
160  *@return    The <code>PeerThread</code> that is handling this command.
161  */
162   public PeerThread getThread() {
163     return thread;
164   }
165 
166   /***
167  *  Returns the parameters sent to the server as an unparsed string.
168  *
169  *  @return    The unparsed parameters sent to the server.
170  */
171   public String getUnparsedParams() {
172     return unparsedParams;
173   }
174 
175   /***
176  *  Forces the command to send a reply back to the client.
177  *
178  *@throws  IndyException  If an exception occurs whilst writing the reply to the socket.
179  */
180   public void sendReply() throws IndyException {
181     performReply = false;
182     commandHandler.getCommandHandlers().getServer().getReplyTexts()
183               .updateText(this.reply);
184     thread.getConnection().writeRFCReply(reply);
185   }
186 
187   /***
188  * Sets the {@link PeerThread} that this <code>Command</code> is being handled by.
189  *
190  * @param thread The <code>PeerThread</code> that this command is being handled by.
191  */
192   void setThread(PeerThread thread) {
193     this.thread = thread;
194   }
195 
196   /***
197  * Sets the raw character data for this command.
198  *
199  * @param rawLine The raw character data for this command
200  */
201   void setRawLine(String rawLine) {
202     this.rawLine = rawLine;
203   }
204 
205   /***
206  * Sets the {@link CommandHandler} that is proessing this command
207  *
208  * @param commandHandler The <code>CommandHandler</code> that is handling this <code>Command</code>
209  * @see #getCommandHandler()
210  */
211   void setCommandHandler(CommandHandler commandHandler) {
212     this.commandHandler = commandHandler;
213   }
214 
215   /***
216    * DOCUMENT ME!
217    *
218    * @param unparsedParams DOCUMENT ME!
219    */
220   void setUnparsedParams(String unparsedParams) {
221     this.unparsedParams = unparsedParams;
222   }
223 }
This page was automatically generated by Maven